package easy;

public class Solution_860 {

    public boolean lemonadeChange(int[] bills) {
        int fiveNum = 0, tenNum = 0;
        for (int bill : bills) {
            if (bill == 5) {
                fiveNum++;
            } else if (bill == 10) {
                if (fiveNum < 1) {
                    return false;
                }
                fiveNum--;
                tenNum++;
            } else {
                if (tenNum >= 1 && fiveNum >= 1) {
                    tenNum--;
                    fiveNum--;
                } else if (fiveNum >= 3) {
                    fiveNum -= 3;
                } else {
                    return false;
                }
            }
        }
        return true;
    }

    public static void main(String[] args) {
        Solution_860 model = new Solution_860();
        System.out.println(model.lemonadeChange(new int[]{5, 5, 5, 10, 20}));
        System.out.println(model.lemonadeChange(new int[]{5, 5, 10, 10, 20}));
        System.out.println(model.lemonadeChange(new int[]{5, 5, 10}));
        System.out.println(model.lemonadeChange(new int[]{10, 10}));
    }
}
